package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.mapper.BaseTransferManageMapper;
import com.kaili.basic.pojo.entity.BaseTransferExport;
import com.kaili.basic.pojo.entity.BaseTransferManage;
import com.kaili.basic.pojo.vo.BaseTransferVO;
import com.kaili.basic.service.BaseTransferManageService;
import com.kaili.common.util.LoginDetailUtils;
import com.kaili.common.util.PinYinUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by renzhikun on 18-4-25.
 */

@Service
@Transactional
public class BaseTransferManageServiceImpl implements BaseTransferManageService {

    @Autowired
    private BaseTransferManageMapper transferManageMapper;

    @Override
    public void addTrans(BaseTransferManage transferManage) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        if (uid != null) {
            transferManage.setCreateBy(uid.longValue());
            transferManage.setModifyBy(uid.longValue());
            transferManage.setPinyin(PinYinUtil.toPinYin(transferManage.getTransferName()));
            transferManage.setInitial(PinYinUtil.toSimplePinYin(transferManage.getTransferName()));
            transferManageMapper.addTrans(transferManage);
        }
    }

    @Override
    public void deleteTrans(Long id) {
        Map<String, Object> map = new HashMap();
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        if (uid != null) {
            map.put("modifyBy", uid.longValue());
            map.put("transferId",id);
            transferManageMapper.deleteTrans(map);
        }
    }

    @Override
    public void updateTrans(BaseTransferManage transferManage) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        if (uid != null) {
            transferManage.setModifyBy(uid.longValue());
            transferManage.setPinyin(PinYinUtil.toPinYin(transferManage.getTransferName()));
            transferManage.setInitial(PinYinUtil.toSimplePinYin(transferManage.getTransferName()));
            transferManageMapper.updateTrans(transferManage);
        }
    }

    @Override
    public Page<BaseTransferManage> findTransBy(Page<BaseTransferManage> page, BaseTransferManage transferManage) {
        List<BaseTransferManage> transferManages = transferManageMapper.findTransBy(page, transferManage);
        return page.setRecords(transferManages);
    }

    @Override
    public BaseTransferManage getTransByTid(Long transferId) {
        return transferManageMapper.getTransByTid(transferId);
    }

    @Override
    public List<BaseTransferManage> findTransByTransferNameAndContacts(BaseTransferManage transferManage) {
        return transferManageMapper.findTransByTransferNameAndContacts(transferManage);
    }

    @Override
    public List<Long> getTransferIdForList() {
        return transferManageMapper.getTransferIdForList();
    }

    @Override
    public List<BaseTransferVO> getTransLikeTransferId(@Param("str") String str) {
        return transferManageMapper.getTransLikeTransferId(str);
    }

    @Override
    public List<BaseTransferExport> queryTransferExport(Map<String, Object> map) {
        return transferManageMapper.queryTransferExport(map);
    }
}
